using System.Reflection;
using Workflow.Application;
using Workflow.Application.Step;
using Workflow.Domain;
using Workflow.Host;
using Yitter.IdGenerator;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(x => x.IncludeXmlComments(AppContext.BaseDirectory + "Workflow.Host.xml", true));
builder.Services.AddAutoMapper(typeof(MyProfile));
builder.Services.AddScoped<IWorkflowService, WorkflowService>();
YitIdHelper.SetIdGenerator(new IdGeneratorOptions());
builder.Services.AddDbContext<WorkflowContext>();
builder.Services.AddWorkflow(x =>
{
    x.UseMySQL(builder.Configuration.GetConnectionString("MySQL"), false, false);
});
builder.Services.AddWorkflowDSL();
builder.Services.AddScoped<StartStep>();
builder.Services.AddScoped<AuditStep>();
builder.Services.AddScoped<EndStep>();
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}


app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
app.UseWorkflow();
app.Run();
